## -*- coding: utf-8 -*-
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    ${h.stylesheet_link(url('/yui/2.8.2r1/reset-fonts-grids/reset-fonts-grids.css'))}
    ${h.stylesheet_link(url('/css/main.css'))}
    ${self.colorsCSS()}
    ${h.javascript_link(url('/yui/2.8.2r1/yahoo-dom-event/yahoo-dom-event.js'))}
    ${h.javascript_link(url('/yui/2.8.2r1/connection/connection_core-min.js'))}
    ${h.javascript_link(url('/javascript/functions.js'))}
    ${h.stylesheet_link(url('/yui/2.8.2r1/menu/assets/skins/sam/menu.css'))}
    ${h.javascript_link(url('/yui/2.8.2r1/yahoo-dom-event/yahoo-dom-event.js'))}
    ${h.javascript_link(url('/yui/2.8.2r1/container/container_core-min.js'))}
    ${h.javascript_link(url('/yui/2.8.2r1/menu/menu-min.js'))}
    ${self.writeJavascriptToHead()}

<%
if not session.has_key('user_username'):
    disabledDict = {
        'forms': ', disabled: true',
        'files': ', disabled: true',
        'collections': ', disabled: true',
        'dictionary': ', disabled: true',
        'people': ', disabled: true',
        'tags': ', disabled: true',
        'sources': ', disabled: true',
        'settings': ', disabled: true'
    }
else:
    disabledDict = {}
    
def disabled(key):
    try:
        return disabledDict[key]
    except KeyError:
        return u''
%>

    <script type="text/javascript">
        YAHOO.util.Event.onDOMReady(function () {

            var aItemData = [
                {text: "Forms", url: '${url(controller='form', action='browse')}'${disabled('forms')}, submenu: {id: "formmenu",
                    itemdata: [
                        {text: "Add a Form", helptext: "(a)", url: '${url(controller='form', action='add')}'},
                        {text: "Search Forms", helptext: "(s)", url: '${url(controller='form', action='search')}'},
                        {text: "Browse Forms", helptext: "(f)", url: '${url(controller='form', action='browse')}'}
                    ]}
                },
                {text: "Files", url: '${url(controller='file', action='browse')}'${disabled('files')}, submenu: {id: "filemenu",
                    itemdata: [
                        {text: "Add a File", helptext: "(q)", url: '${url(controller='file', action='add')}'},
                        {text: "Search Files", helptext: "(w)", url: '${url(controller='file', action='search')}'},
                        {text: "Browse Files", helptext: "(r)", url: '${url(controller='file', action='browse')}'}
                    ]}
                },
                {text: "Collections"${disabled('collections')}, url: '${url(controller='collection', action='browse')}',
                    submenu: {id: "collectionmenu", itemdata: [
                        {text: "Add a Collection", helptext: "(z)",
                            url: '${url(controller='collection', action='add')}'},
                        {text: "Search Collections", helptext: "(x)",
                            url: '${url(controller='collection', action='search')}'},
                        {text: "Browse Collections", helptext: "(c)",
                            url: '${url(controller='collection', action='browse')}'}
                    ]}
                },
                {text: "Dictionary"${disabled('dictionary')}, url: '${url(controller='dictionary', action='browse')}',
                    submenu: {id: "dictionarymenu", itemdata: [
                        {text: "Search Dictionary", url: '${url(controller='dictionary', action='search')}'},
                        {text: "Browse Dictionary", helptext: "(d)",
                            url: '${url(controller='dictionary', action='browse')}'}
                    ]}
                },
                {text: "People", url: '${url(controller='people', action='index')}'${disabled('people')},
                    submenu: {id: "peoplemenu", itemdata: [
                        {text: "View All", helptext: "(p)", url: '${url(controller='people', action='index')}'},
                        {text: "Speakers", url: '${url(controller='people', action='index', anchor='speakers')}',
                            submenu: {id: "speakersmenu", itemdata: [
                                {text: "Add a Speaker", url: '/speaker/add'}
                            ]}
                        },
                        {text: "Users", url: '/people#users',
                            submenu: {id: "usersmenu", itemdata: [
                                {text: "Add a User", url: '/researcher/add'}
                            ]}
                        }
                    ]}
                },
                {text: "Tags", url: '/tag'${disabled('tags')}, submenu: {id: "tagsmenu", itemdata: [
                        {text: "View All", helptext: "(t)", url: '/tag'},
                        {text: "Keywords", url: '/tag#keywords',
                            submenu: {id: "keywordsmenu", itemdata: [
                                {text: "Add a Keyword", url: '/key/add'}
                            ]}
                        },
                        {text: "Syntactic Categories", url: '/tag#categories'${disabled('categories')},
                            submenu: {id: "categoriesmenu", itemdata: [
                                {text: "Add a Category", url: '/category/add'}
                            ]}
                        },
                        {text: "Elicitation Methods", url: '/tag#methods'${disabled('methods')},
                            submenu: {id: "methodsmenu", itemdata: [
                                {text: "Add an Elicitation Method", url: '/method/add'}
                            ]}
                        }
                    ]}
                },
                {text: "Sources", url: '/source'${disabled('sources')}, submenu: {id: "sourcesmenu", itemdata: [
                        {text: "Add a Source", url: '/source/add'},
                        {text: "Browse Sources", url: '/source'}
                    ]}
                },
                {text: "Help", url: '/help/applicationhelp'${disabled('help')},
                    submenu: {id: "helpmenu", itemdata: [
                        {text: "Help Page", helptext: '(h)', url: '/help/applicationhelp'},
                        {text: "OLD User Guide", url: '/help/olduserguide'}
                    ]}
                },
                {text: "Settings", url: '/settings'${disabled('settings')},
                    submenu: {id: "settingsmenu", itemdata: [
                        {text: "View Settings", url: '/settings'},
                        {text: "Edit Settings", url: '/settings/edit'}
                    ]}
                },
                {text: "Account"${disabled('account')}, submenu: {id: "accountmenu", itemdata: [
% if session.has_key('user_id'):
                        {text: "My Page", url: '/researcher/view/${session['user_id']}',
                            submenu: {id: "mypagemenu", itemdata: [
                                {text: "Edit My Page", url: '/researcher/edit/${session['user_id']}'}
                            ]}
                        },
                        {text: "My Settings", url: '/researcher/settings/${session['user_id']}',
                            submenu: {id: "mysettingsmenu", itemdata: [
                                {text: "Edit My Settings",
                                    url: '/researcher/editsettings/${session['user_id']}'}
                            ]}
                        },
                        {
                            text: "My Memory",
                            url: '${url(controller='memory', action='index')}',
                            helptext: '(m)'
                        },
                        {text: "Logout", helptext: '(l)', url: '/login/logout'}
% else:
                        {text: "Login", helptext: '(l)', url: '/login/login'}
% endif
                    ]}
                }
            ];
            var oMenuBar = new YAHOO.widget.MenuBar("mymenubar", {
                autosubmenudisplay: true});
            oMenuBar.addItems(aItemData);
            oMenuBar.render('topmenubar');

            function getEmptyAnchor(item)
            {
                var temp = '';
                if (item.hasOwnProperty('helptext'))
                {
                    temp = '<a href="' + item['url'] + '" accesskey="' +
                        item['helptext'].charAt(1) + '"></a>\n';
                }
                return temp;
            }
            
            function getAccessKey(itemList)
            {
                var temp = '';
                for (var i = 0; i < itemList.length; i++) 
                {
                    var item = itemList[i];
                    temp += getEmptyAnchor(item);
                    if (item.hasOwnProperty('submenu'))
                    {
                        temp += getAccessKey(item['submenu']['itemdata']);
                    }
                }
                return temp;
            }
            document.getElementById('keyboardshortcuts').innerHTML = getAccessKey(aItemData);
        });
    </script>
    <title>${self.title()}</title>
</head>

<%
topPrimaryMenuItems = app_globals.getTopPrimaryMenuItems()
topSecondaryMenuItems = app_globals.getTopSecondaryMenuItems(url.current())
sideMenuItems = app_globals.sideMenuItems
activeMenuItems = app_globals.getActiveMenuItems(url.current())
%>


<body class="yui-skin-sam">
<a name="top"></a>
<div id="doc">
    <div id="hd">${self.header()}</div>
    <div id="topmenubar"></div>
    <div id="keyboardshortcuts"></div>
    <div id="bd">
        ${self.heading()}
        ${self.flash()}
        ${next.body()}
    </div>
    <div id="ft">
        ${self.footer()}
    </div>
</div>

</body>
</html>


<%def name="getMenuClass(item, activeMenuItems)">
    % if item['id'] in activeMenuItems:
        class = 'selected'
    % endif
</%def>

<%def name="getMenuItemLink(item, activeMenuItems)">
    <li><a ${self.getMenuClass(item, activeMenuItems)}\
        href="${url(item['url'])}"\
    % if 'accesskey' in item:
        accesskey="${item['accesskey']}"\
    % endif
    % if 'title' in item:
        <% title = item['title'] %>
        % if 'accesskey' in item:
            <% title += ' <' + item['accesskey'] + '>' %>
        % endif
        title="${title}" 
    % endif
    >${item['name']}</a></li>
</%def>

<%def name="title()">
 <%
  try:
    headingText = ': %s' % c.HTMLTitle
  except AttributeError:
    headingText = ''
 %>
 OLD${headingText}
</%def>

<%def name="writeJavascriptToHead()"></%def>

<%def name="head()"></%def>

<%def name="header()">
 <%
  objectLanguageName = app_globals.objectLanguageName
  temp = str(2000 / (len(app_globals.objectLanguageName) + 1))
  titleWordsStyle = h.literal('style=\"font-size: %s%s;\"' % (temp, '%'))
  headerImageName = app_globals.headerImageName
  if headerImageName:
    style = h.literal(
        """style="background: #fff url('/file/retrieve/%s') no-repeat bottom
        left;" """ % headerImageName
    )
  else:
    style = ''
 %>
 <div id="header" ${style}>
  <div id="titleWords"><a href='${url(controller='home', action='index')}'>${objectLanguageName}</a></div>
  <div id="onlinelinguisticdatabase">Online Linguistic Database</div>
 </div>
</%def>

<%def name="topPrimaryMenu(topPrimaryMenuItems, activeMenuItems)">
    <div id="topTopMenu">
        <ul>
            % for item in topPrimaryMenuItems:
                ${self.getMenuItemLink(item, activeMenuItems)}\
            % endfor
        </ul>
    </div>
</%def>

<%def name="topSecondaryMenu(topSecondaryMenuItems, activeMenuItems)">
    % if topSecondaryMenuItems:
    <div id="topMenu">
        <ul>
            % for item in topSecondaryMenuItems:
                ${self.getMenuItemLink(item, activeMenuItems)}\
            % endfor
        </ul>
    </div>
    % endif
</%def>

<%def name="sideMenu(sideMenuItems, activeMenuItems)">
        <p class="sideMenuLabel"><a href="${url('/form/browse')}"
        title="browse all Forms <f>" accesskey="f"
            % if '/form/browse' in url.current():
                class = 'selected'
            % endif
        >FORMS</a></p>
        <ul>
            % for item in sideMenuItems['form']:
                ${self.getMenuItemLink(item, activeMenuItems)}\
            % endfor
        </ul>
        <p class="sideMenuLabel"><a href="${url('/file/browse')}"
        title="browse all Files <r>" accesskey="r"
            % if '/file/browse' in url.current():
                class = 'selected'
            % endif
        >FILES</a></p>
        <ul>
            % for item in sideMenuItems['file']:
                ${self.getMenuItemLink(item, activeMenuItems)}\
            % endfor
        </ul>
        <p class="sideMenuLabel"><a href="${url('/collection/browse')}"
        title="browse all Collections <c>" accesskey="c"
            % if '/collection/browse' in url.current():
                class = 'selected'
            % endif
        >COLLECTIONS</a></p>
        <ul>
            % for item in sideMenuItems['collection']:
                ${self.getMenuItemLink(item, activeMenuItems)}\
            % endfor
        </ul>
</%def>

<%def name="heading()"><h1 class="heading"></h1></%def>

<%def name="footer()">
    <%namespace file="/base/javascriptDefs.html" name="javascriptDefs"
    import="closeHelpDivScript, fillHelpDivScript"/>
    ${closeHelpDivScript()}
    ${fillHelpDivScript()}
    <p><a href="#top">Top ^</a></p>
    <div id="helpDiv">
      <a href='#' title="Close the help window" id="closeButton"
         onclick="closeHelpDiv();return false;">x</a>
      <div id="helpDivInner">
        Help me
      </div>
    </div>
</%def>

<%def name="flash()">
    % if session.has_key('flash'):
    <div id="flash"><p>${session.get('flash')}</p></div>
    <%
        del session['flash']
        session.save()
    %>
    % endif
</%def>

<%def name="login()">
<div id="loginInfo">
 % if session.has_key('user_username'):
  <a href="${url(controller='researcher', action='view', id=session['user_id'])}"
     title="Visit your personal page">${session['user_username']}</a>
  <a href="${url(controller='login', action='logout')}" accesskey="l"
     title="click here to log out of the system <l>"> | logout</a>
 % else:
  <a href="${url(controller='login', action='login')}" accesskey="l"
     title="click here to log in to the system <l>">login</a>
 % endif  
</div>
</%def>


<%def name="colorsCSS()">
    ${h.stylesheet_link(url('/css/colors/%s' % app_globals.colorsCSS))}
</%def>